package middleware

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func CorsMiddleware() gin.HandlerFunc {
	config := cors.DefaultConfig()
	config.AllowOrigins = []string{"http://127.0.0.1:3100"}                                     // 允许什么域名访问，支持多个域名
	config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}                   // 允许的 HTTP 方法
	config.AllowHeaders = []string{"Authorization", "Origin", "Content-Length", "Content-Type"} // 允许的 HTTP 头
	return cors.New(config)
}
